﻿
using Prism.Commands;
using Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using wms_wpf.Apiservice;
using wms_wpf.Dto;
using wms_wpf.InPut;
using wms_wpf.Views;

namespace wms_wpf.ViewModels
{
    public class MaterialViewModel:BindableBase
    {
        private readonly MaterialView materialView;

        public MaterialViewModel(MaterialView materialView)
        {
            this.materialView = materialView;
            View_MaterialsDtos = new List<View_MaterialsDto>();
            InPut_ViewService=new InPut_ViewService();
            InPut_ViewService.PageIndex = 1;
            InPut_ViewService.PageSize = 20;
            GetList_View_MaterialsCommand = new DelegateCommand(GetList_View_Materials);
            service = new ViewService();
            GetList_View_Materials();
        }


        private List<View_MaterialsDto> view_MaterialsDtos;
        public  List< View_MaterialsDto> View_MaterialsDtos
        {
            get { return view_MaterialsDtos; }
            set { view_MaterialsDtos = value;RaisePropertyChanged();}
        }

        public DelegateCommand GetList_View_MaterialsCommand { get; set; }
        private InPut_ViewService inPut_ViewService;
        public InPut_ViewService InPut_ViewService
        {
            get { return inPut_ViewService; }
            set { inPut_ViewService = value;RaisePropertyChanged(); }
        }
        private long count;
        public long Count
        {
            get { return count; }
            set { count = value; RaisePropertyChanged(); }
        }
        private long pagecount;
        public long PageCount
        {
            get { return pagecount; }
            set { pagecount = value; RaisePropertyChanged(); }
        }
        public IViewService service { get; set; }

        private async void GetList_View_Materials()
        {
            Tuple<List<View_MaterialsDto>, long?, long?> tuple = await  service.GetList_View_Materials(InPut_ViewService);
            if (tuple == null)
            {
                return;
            }
            View_MaterialsDtos = tuple.Item1;
            Count = (long)tuple.Item2;
            PageCount = (long)tuple.Item3;
        }


    }
}
